package com.lsmo.android.carfans.activity.car;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.lsmo.android.carfans.R;
import com.lsmo.android.carfans.app.widget.RemoteImageView;
import com.lsmo.android.carfans.model.car.BrandTypeThread;
import com.lsmo.android.util.ArrayListAdapter;

public class BrandTypeAdapter extends ArrayListAdapter<BrandTypeThread>{
	
	ArrayList<BrandTypeThread> list;
	public final static int TYPE_SECTION_HEADER = 0;
	
	public BrandTypeAdapter(Context context) {
		super(context);
		// TODO Auto-generated constructor stub
	}
	 
	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		View localView1 = convertView;
		ViewHolder localViewHolder;
		LayoutInflater mInflater = ((Activity) mContext).getLayoutInflater();
		
		if(localView1 == null){
			localView1 = mInflater.inflate(R.layout.car_adapter_brandlist, null);
			localViewHolder = new ViewHolder();
			
			localViewHolder.name = (TextView)localView1.findViewById(R.id.brandname);
			localViewHolder.price = (TextView)localView1.findViewById(R.id.brandprice);
			localViewHolder.price2 = (TextView)localView1.findViewById(R.id.brandprice2);
			localViewHolder.imageview = (RemoteImageView)localView1.findViewById(R.id.carbrandimage);
		    
			localView1.setTag(localViewHolder);
		} else {
			localViewHolder = (ViewHolder) localView1.getTag();
		}
		
		//指导价
		StringBuilder localStringBuilder1 = new StringBuilder("指导价:");
		String referPrice = ((BrandTypeThread)mList.get(position)).getCsReferPrice();
		localStringBuilder1.append(referPrice).append("万");
		localViewHolder.price.setText(localStringBuilder1.toString());
		
		//经销商报价
	    StringBuilder localStringBuilder2 = new StringBuilder("经销商报价:");
	    String rangePrice = ((BrandTypeThread)mList.get(position)).getCsPriceRange();
	    localStringBuilder2.append(rangePrice);
		localViewHolder.price2.setText(localStringBuilder2.toString());
		
		//排量
		String carNameString = ((BrandTypeThread)mList.get(position)).getModelName();
		localViewHolder.name.setText(carNameString);
		
		localViewHolder.imageview.setVisibility(View.GONE);
		
		return localView1;
	}
	
	public boolean areAllItemsSelectable() {
		return false;
	}

	public boolean isEnabled(int position) {
		return (getItemViewType(position) != TYPE_SECTION_HEADER);
	}
	
   class ViewHolder
   {
	   RemoteImageView imageview;
		TextView name;
		TextView price;
		TextView price2;
   }

}
